package com.csgc.camera.biz.other.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.recyclerview.widget.GridLayoutManager
import com.csgc.camera.base.BaseBindingActivity
import com.csgc.camera.bean.ChooseMaskStyle
import com.csgc.camera.biz.MainActivity
import com.csgc.camera.biz.other.adapter.ChooseMaskStyleAdapter
import com.csgc.camera.storage.CommonPreference
import com.csgc.camera.storage.MaskPreference
import com.csgc.camera.util.clickWithTrigger
import com.cysd.spsyxj.R
import com.cysd.spsyxj.databinding.ActivityChooseMaskStyleBinding
import com.gyf.immersionbar.ktx.immersionBar
import com.hjq.toast.ToastUtils

class ChooseMaskStyleActivity:BaseBindingActivity<ActivityChooseMaskStyleBinding>(ActivityChooseMaskStyleBinding::inflate) {

    companion object{
        fun launch(context: Context){
            context.startActivity(Intent(context,ChooseMaskStyleActivity::class.java))
        }
    }

    private var maskType = -1
    private var maskId = -1
    private val adapter:ChooseMaskStyleAdapter by lazy {
        val adapter = ChooseMaskStyleAdapter(this, ArrayList())
        adapter.listener = object :ChooseMaskStyleAdapter.OnItemChooseListener{
            override fun onItemChoose(type: Int, id: Int) {
                maskType = type
                maskId = id
            }
        }
        adapter
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        immersionBar {
            fitsSystemWindows(true)

            statusBarColor(R.color.white)
            statusBarDarkFont(true)

        }

        val list = ArrayList<ChooseMaskStyle>()
        val manager = GridLayoutManager(this,2)
        manager.orientation = GridLayoutManager.VERTICAL
        binding.rvMaskTypeList.layoutManager = manager

        list.add(ChooseMaskStyle("建筑/工程业",9,0))
        list.add(ChooseMaskStyle("物业管理/安保",4,0))
        list.add(ChooseMaskStyle("装修/装饰",6,0))
        list.add(ChooseMaskStyle("餐饮业",8,0))

        list.add(ChooseMaskStyle("环境卫生",10,0))
        list.add(ChooseMaskStyle("物流运输",5,0))
        list.add(ChooseMaskStyle("家政服务",11,0))
        list.add(ChooseMaskStyle("服务业",6,0))
        list.add(ChooseMaskStyle("互联网/信息技术",0,0))
        list.add(ChooseMaskStyle("汽车服务",3,0))
        list.add(ChooseMaskStyle("制造业",0,0))
        list.add(ChooseMaskStyle("快递/装卸/仓储",0,0))
        adapter.updateContent(list)
        binding.rvMaskTypeList.adapter = adapter


        binding.tvJumpMain.clickWithTrigger {
            MaskPreference.instance.setMaskType(0)
            MaskPreference.instance.setMaskId(0)

            CommonPreference.instance.setFirstChooseMask(true)
            MainActivity.launch(this)

            finish()
        }

        binding.tvContinueMain.clickWithTrigger {

            if (maskType == -1){
                ToastUtils.show("请选择行业")
                return@clickWithTrigger
            }
            MaskPreference.instance.setMaskType(maskType)
            MaskPreference.instance.setMaskId(maskId)

            ChooseIdentityActivity.launch(this)
            finish()
        }

        CommonPreference.instance.setFirstChooseMask(true)

    }



}